1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<stdio.h>
#define N 7
void MapColor(int dist[N][N],int s[N]) { int color,area,k; s[0]=1; area=1; color=1; while(area<N) {
while(color<=4) { if(area>=N) break; k=0; while((k<area)&&(s[k]*dist[area][k]!=color)) k++; if(k<area) color++; else { s[area]=color; area++; color=1; } } if(color>4) { area=area-1; color=s[area]+1; } } } void main() { int dist[N][N]={{0,1,1,1,1,1,0}, {1,0,0,0,0,1,0}, {1,0,0,1,1,0,0}, {1,0,1,0,1,1,0}, {1,0,1,1,0,1,0}, {1,1,0,1,1,0,0}, {0,0,0,0,0,0,0}}; int s[N]={0}; MapColor(dist,s); printf("地图区域标号为1~7的染色情况为:"); for(int i=0;i<N;i++) printf("%d ",s[i]); printf("\n"); }
|